package com.sunlands.zlcx.usercenter.service.status;

import com.sunlands.zlcx.usercenter.domain.UsersTargetRelationDO;
import com.sunlands.zlcx.usercenter.service.status.common.AbstractStudyStatus;
import com.sunlands.zlcx.usercenter.util.BeanPropertiesUtil;
import com.sunlands.zlcx.usercenter.vo.UsersStudyInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 选择目标
 *
 * @author gaoyanfeng
 * @create 2019-04-28 13:57
 **/
@Component
@Slf4j
public class SelectTarget extends AbstractStudyStatus implements BeanPropertiesUtil {
    @Override
    public void handle(UsersStudyInfoVO usersStudyInfoVO, UsersTargetRelationDO usersTargetRelationDO) {
        usersStudyInfoVO.setRelateId(usersTargetRelationDO.getId());
        usersStudyInfoVO.setStudyInfoName(usersTargetRelationDO.getTargetName());
        sendMessage(usersStudyInfoVO.getUserId(), "选择了新的学习目标" + usersTargetRelationDO.getTargetName());

        // 保存学习生活
        saveStudyInfo(usersStudyInfoVO, usersTargetRelationDO);
        // 同步到用户表
        usersService.updateCurrentLearnTarget(usersTargetRelationDO.getUserId(), usersTargetRelationDO.getTargetId(), usersTargetRelationDO.getTargetName());
    }
}
